<?php

/*require_once '../common/RootPath.php';
RootPath::importPath("entity/Tag.php");*/

class Article  implements JsonSerializable
{
    private $id;
    private $title;
    private $summary;
    private $commentCounts;
    private $viewCounts;
    private $weight;

    //创建时间
    private $createDate;

    private $author;

    /*private ArticleBodyVo body;*/
    /*private List<categoryvo> categorys;*/


    private $tags = [];

    /**
     * @param $id
     * @param $title
     * @param $summary
     * @param $commentCounts
     * @param $viewCounts
     * @param $weight
     * @param $createDate
     * @param $author
     * @param array $tags
     */
    public function __construct($id, $title, $summary, $commentCounts, $viewCounts, $weight, $createDate)
    {
        $this->id = $id;
        $this->title = $title;
        $this->summary = $summary;
        $this->commentCounts = $commentCounts;
        $this->viewCounts = $viewCounts;
        $this->weight = $weight;
        $this->createDate = $createDate;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     */
    public function setId($id): void
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @param mixed $title
     */
    public function setTitle($title): void
    {
        $this->title = $title;
    }

    /**
     * @return mixed
     */
    public function getSummary()
    {
        return $this->summary;
    }

    /**
     * @param mixed $summary
     */
    public function setSummary($summary): void
    {
        $this->summary = $summary;
    }

    /**
     * @return mixed
     */
    public function getCommentCounts()
    {
        return $this->commentCounts;
    }

    /**
     * @param mixed $commentCounts
     */
    public function setCommentCounts($commentCounts): void
    {
        $this->commentCounts = $commentCounts;
    }

    /**
     * @return mixed
     */
    public function getViewCounts()
    {
        return $this->viewCounts;
    }

    /**
     * @param mixed $viewCounts
     */
    public function setViewCounts($viewCounts): void
    {
        $this->viewCounts = $viewCounts;
    }

    /**
     * @return mixed
     */
    public function getWeight()
    {
        return $this->weight;
    }

    /**
     * @param mixed $weight
     */
    public function setWeight($weight): void
    {
        $this->weight = $weight;
    }

    /**
     * @return mixed
     */
    public function getCreateDate()
    {
        return $this->createDate;
    }

    /**
     * @param mixed $createDate
     */
    public function setCreateDate($createDate): void
    {
        $this->createDate = $createDate;
    }

    /**
     * @return mixed
     */
    public function getAuthor()
    {
        return $this->author;
    }

    /**
     * @param mixed $author
     */
    public function setAuthor($author): void
    {
        $this->author = $author;
    }

    public function getTags(): array
    {
        return $this->tags;
    }

    public function setTags($tags): void
    {
        $this->tags[] = $tags;
    }

    public function jsonSerialize()
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'summary' => $this->summary,
            'commentCounts' => $this->commentCounts,
            'viewCounts' => $this->viewCounts,
            'weight' => $this->weight,
            'createDate' => $this->createDate,
            'author' => $this->author,
            'tags' => $this->tags
        ];
    }
}

/*$article = new Article();
$article->setAuthor("jmz");
$article->setTitle("jdk環境配置");
$article->setCreateDate('2022-11-10');


$tag1 = new Tag();
$tag1->setId(101);
$tag1->setName("新聞");

$tag2 = new Tag();
$tag2->setId(102);
$tag2->setName("音樂");

$article->setTags($tag1);
$article->setTags($tag2);

$json = json_encode($article, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
echo $json;*/






